package com.gopay.common.cps.dao.gsrt.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.trans.TxnStaCode;
import com.gopay.common.cps.dao.gsrt.GsrtLoanDisbursementsMasterDao;
import com.gopay.common.domain.gsrt.GsrtLoanDisbursementsMaster;

/**
 * 
 * @Description: 放款
 * @author hougn
 * @date 2016年1月27日 上午10:47:51 
 *
 */
@Repository("gsrtLoanDisbursementsMasterDao")
public class GsrtLoanDisbursementsMasterDaoImpl extends BaseDAOImpl<GsrtLoanDisbursementsMaster, Serializable>
        implements GsrtLoanDisbursementsMasterDao {

    @Override
    public GsrtLoanDisbursementsMaster findByGopayOrderId(String gopayOrderId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtLoanDisbursementsMaster.class);
        criteria.add(Restrictions.eq("gopayOrderId", gopayOrderId));
        List<GsrtLoanDisbursementsMaster> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }
    
    @Override
    public List<GsrtLoanDisbursementsMaster> findByMerCustIdAndBidNo(String merCustId, String bidNo) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtLoanDisbursementsMaster.class);
        criteria.add(Restrictions.eq("merCustId", merCustId));
        criteria.add(Restrictions.eq("bidNo", bidNo));
        criteria.add(Restrictions.eq("txnStaCd", TxnStaCode.TXN_STA_CD_20000.value));
        List<GsrtLoanDisbursementsMaster> list = this.findByCriteria(criteria);
        return list;
    }
    
    @Override
    public List<GsrtLoanDisbursementsMaster> findByMerCustIdAndBidNoAndTxnStaCdIn(String merCustId, String bidNo, List<Integer> txnStaCdList) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtLoanDisbursementsMaster.class);
        criteria.add(Restrictions.in("txnStaCd", txnStaCdList));
        criteria.add(Restrictions.eq("merCustId", merCustId));
        criteria.add(Restrictions.eq("bidNo", bidNo));
        List<GsrtLoanDisbursementsMaster> list = this.findByCriteria(criteria);
        return list;
    }
}
